package com.example.playbox

import androidx.appcompat.app.AppCompatActivity
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.ImageButton


class MainActivity : AppCompatActivity(), View.OnClickListener {
    private lateinit var btUpdatee: Button
    private lateinit var btDeletee: Button
    private lateinit var btRead: Button

    @SuppressLint("WrongViewCast")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main) //为这个activity的运行分配内存，即首页

        val ibPersonalCenter: ImageButton = findViewById(R.id.bt_personal)
        //跳转到个人中心界面，
        ibPersonalCenter.setOnClickListener {
            val intent = Intent(this@MainActivity, PersonalCenterActivity::class.java)
            startActivity(intent)
        }

        val ibAdd: ImageButton = findViewById(R.id.bt_add)
        ibAdd.setOnClickListener {
            val intent = Intent(this@MainActivity, AddGamesActivity::class.java)
            startActivity(intent)
        }

        btUpdatee = findViewById(R.id.bt_updatee)
        btUpdatee.setOnClickListener(this)

        btDeletee = findViewById(R.id.bt_deletee)
        btDeletee.setOnClickListener(this)

        btRead = findViewById(R.id.bt_read)
        btRead.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        //通过switch方法跳转到相应界面
        when (v.id) {
            R.id.bt_updatee -> {
                val intentQuery = Intent(this@MainActivity, UpdateGamesActivity::class.java)
                startActivity(intentQuery)
            }
            R.id.bt_deletee -> {
                val intentUpdate = Intent(this@MainActivity, DeleteGamesActivity::class.java)
                startActivity(intentUpdate)
            }
            R.id.bt_read -> {
                val intentDelete = Intent(this@MainActivity, QueryGamesActivity::class.java)
                startActivity(intentDelete)
            }
        }
    }
}